# -*- coding: utf-8 -*-
"""
Created on Sat Mar  8 00:18:01 2014

@author: DTHHA
"""
import sys
import motion
from naoqi import ALProxy

from moveEmotion import moveEmotion
def checkAffectiveMove(motion, emotion, intensity, joint, length):

    m1 = moveEmotion()
    
    m1.setDesiredJoints(joint);

    if (emotion == 1):
    
        m1.moveHappiness(motion,intensity,length);
        
    if (emotion == 2):
        m1.moveSadness(motion,intensity,length);
        
    if (emotion == 3):
        m1.moveAnger(motion,intensity,length);
        
    if (emotion == 4):
        m1.moveSerenity(motion,intensity,length);

    return 0;


if __name__ == "__main__":
    robotIp = "127.0.0.1"
    emotion = 1;
    intensity = 0.5;

    joint = 1;#//Head only by default
    length = 3;
    
    if len(sys.argv) <= 1:
        print "Wrong number of arguments!";
        print "Usage: python mainMoveEmotion.py NAO_IP [emotion] [intensity] [joint] [length]";
        print "Usage: emotion   is in (1(happy), 2(sad), 3(angry), 4(serene))";
        print "Usage: intensity is a float between [0.0, 1.0]";
        print "Usage: joint     is an integer between [1, 7]";
        print "Usage: length    is duration (in integer) of the expression in seconds";
        exit(1);
    else:
        robotIp = sys.argv[1]

    
    try:
        motionProxy = ALProxy("ALMotion", robotIp, 9559)
    except Exception, e:
        print "Could not create proxy to ALMotion"
        print "Error was: ", e
    if len(sys.argv) > 2:
          emotion = int(sys.argv[2]);
      

    if len(sys.argv) > 3:
          intensity = float(sys.argv[3]);
      
    if len(sys.argv) > 4:
          joint = int(sys.argv[4]);
      
    if len(sys.argv) > 5:
          length = int(sys.argv[5]);

    announce = "Expression of ";
    if (emotion == 1):
          announce += "Happiness ";
          
    if (emotion == 2):
          announce += "Sadness ";

    if (emotion == 3):
          announce += "Anger ";
          
    if (emotion == 4):
          announce += "Serenity ";
          
     
    announce += "with intensity={} and joint={} and length={} seconds".format(intensity, joint, length);
    
    print announce
    checkAffectiveMove(motionProxy, emotion, intensity, joint, length);
    print "finished"